/*
 * This file is part of quickLoad, a software for gamers
 *
 * Copyright (C) 2005-2008 Lucas Romero
 *
 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with this program; if not, see <http://www.gnu.org/licenses/>.
 */
using System;
using System.Threading;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Drawing.Drawing2D;

namespace QuickLoad.UI
{
	/// <summary>
	/// Zusammenfassung fr FormSplash.
	/// </summary>
	public class FormSplash : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Timer timer1;
		private System.ComponentModel.IContainer components;
		private System.Windows.Forms.Panel panelDrop;
        private Form m_Parent;
		double fadein = 1;

		public FormSplash(Form parent)
		{
			//
			// Erforderlich fr die Windows Form-Designeruntersttzung
			//
            m_Parent = parent;
			InitializeComponent();

			//
			// TODO: Fgen Sie den Konstruktorcode nach dem Aufruf von InitializeComponent hinzu
			//
			/*for (int i=0;i<100;i++)
			{
				
				Application.DoEvents();
			}*/
		}

		/// <summary>
		/// Die verwendeten Ressourcen bereinigen.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Vom Windows Form-Designer generierter Code
		/// <summary>
		/// Erforderliche Methode fr die Designeruntersttzung. 
		/// Der Inhalt der Methode darf nicht mit dem Code-Editor gendert werden.
		/// </summary>
		private void InitializeComponent()
		{
            this.components = new System.ComponentModel.Container();
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormSplash));
            this.panelDrop = new System.Windows.Forms.Panel();
            this.timer1 = new System.Windows.Forms.Timer(this.components);
            this.SuspendLayout();
            // 
            // panelDrop
            // 
            this.panelDrop.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("panelDrop.BackgroundImage")));
            this.panelDrop.Dock = System.Windows.Forms.DockStyle.Fill;
            this.panelDrop.Location = new System.Drawing.Point(0, 0);
            this.panelDrop.Name = "panelDrop";
            this.panelDrop.Size = new System.Drawing.Size(483, 471);
            this.panelDrop.TabIndex = 0;
            this.panelDrop.Click += new System.EventHandler(this.panelDrop_Click);
            // 
            // timer1
            // 
            this.timer1.Interval = 20;
            this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
            // 
            // FormSplash
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 14);
            this.ClientSize = new System.Drawing.Size(483, 471);
            this.Controls.Add(this.panelDrop);
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
            this.Name = "FormSplash";
            this.ShowInTaskbar = false;
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "FormSplash";
            this.TopMost = true;
            this.Load += new System.EventHandler(this.FormSplash_Load);
            this.ResumeLayout(false);

		}
		#endregion

		private void timer1_Tick(object sender, System.EventArgs e)
		{
			if (fadein > 0)
			{
				//Application.DoEvents();
				this.Opacity = fadein;
				//this.Focus();
				//this.Activate();
				//Application.DoEvents();
				fadein -= 0.01;
				//Application.DoEvents();
			}
			else
			{
				timer1.Enabled = false;
				this.Close();
                m_Parent.Show();
                m_Parent.BringToFront();
                m_Parent.Activate();
			}
			
		}

		private void FormSplash_Load(object sender, System.EventArgs e)
		{
			timer1.Enabled=true;
		}

		private void panelDrop_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
		{
			e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
			int offset=1;
			PointF[] points = {	  new Point(panelDrop.Left+offset, panelDrop.Top+offset),
								  new Point(panelDrop.Right-offset, panelDrop.Top+offset),
								  new Point(panelDrop.Right-offset, panelDrop.Bottom-offset),
								  new Point(panelDrop.Left+offset, panelDrop.Bottom-offset),
								  new Point(panelDrop.Left+offset, panelDrop.Top+offset)};

			Pen pen = new Pen(Color.FromArgb(0, 60, 116), 2); 
			SolidBrush brush1 = new SolidBrush(Color.FromArgb(0, 60, 116));
			LinearGradientBrush brush0 = new LinearGradientBrush(new Rectangle(panelDrop.Left, panelDrop.Top, panelDrop.Width, panelDrop.Height), Color.FromArgb(244, 243, 238), Color.FromArgb(213, 208, 238), 90.0f);
			float[] relativeIntensities = {0.0f, 0.3f, 1.0f};
			float[] relativePositions   = {0.0f, 0.7f, 1.0f};

			Blend blend = new Blend();
			blend.Factors = relativeIntensities;
			blend.Positions = relativePositions;
			brush0.Blend = blend;

			e.Graphics.FillRectangle(brush0, panelDrop.Left, panelDrop.Top, panelDrop.Width, panelDrop.Height);
			e.Graphics.DrawLines(pen, points);

			String text0 = @"quickLoad" + Environment.NewLine + Environment.NewLine + "Uploading" + Environment.NewLine + " Demos" + Environment.NewLine + "&" + Environment.NewLine + "Screenshots" + Environment.NewLine + "made easy";
			Font font = new Font("Microsoft Sans Serif", 26, FontStyle.Bold, GraphicsUnit.Point);
			StringFormat format = new StringFormat();
			format.FormatFlags = StringFormatFlags.FitBlackBox;
			format.Alignment = StringAlignment.Center;
			format.LineAlignment = StringAlignment.Center;
			e.Graphics.DrawString(text0, font, brush1, new Rectangle(panelDrop.Left, panelDrop.Top, panelDrop.Width, panelDrop.Height), format);
		}

		private void panelDrop_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}
	}
}
